class Solution {
    public int numJewelsInStones(String jewels, String stones) {
        int ans = 0;
        Map<Character, Integer> counter = new HashMap<>();
        for (int i = 0 ; i < stones.length(); i++) {
            char ch = stones.charAt(i);
            int count = counter.getOrDefault(ch, 0);
            counter.put(ch, ++count);
        }
        for (int i = 0; i < jewels.length(); i++) {
            ans += counter.getOrDefault(jewels.charAt(i), 0);
        }
        return ans;
    }
}
